// pages/indexsencond/indexsencond.js
var  app=getApp();
var ea = require('../../utils/each.js');

Page({
  /**
   * 页面的初始数据
   */
  data: {

    xiaoqu:[],
    index:0,
    xiala: app.data.url + "/uploads/zhongxue/xiala.png",
    getcampus: app.data.url +'/zhongxue/maoapi/getcampuss',

    itemsdd: [
      {name: "成都校区",checked:true},
      {name: "北京校区", checked: false },
      {name: "上海校区", checked: false },
      {name: "广东校区", checked: false },
    
  ]
  },


  //点击校区选择
  bindPickerChange:function(e){
    console.log(e);
    var index = parseInt(e.detail.value);
    var xiaoqu = this.data.xiaoqu;
    ea.each(xiaoqu,function(i,v){
        if(i==index){
          wx.setStorageSync('xiaoqu', v.id);
          wx.switchTab({
            url: '/pages/index/index',
          })
        }
    })

  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var user = wx.getStorageSync('user');
    var that = this;
    wx.request({
      url:that.data.getcampus ,
      data: {token:user.token},
      header: {},
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: function(res) {
        var data = res.data;
        console.log(data);
        if(data.code==200){
          var xiaoqu = data.data;
          var newxiaoqu = [];
          ea.each(xiaoqu,function(i,v){
            v.checked = false;
            newxiaoqu.push(v);
          })
          that.setData({ xiaoqu: newxiaoqu });
          // wx.setStorageSync('xiaoqu', data.data[0].id);

        }else{
          wx.showToast({
            title: data.msg,
            icon: 'none',
            mask: true,
            duration:app.data.quanbushijian
          })
        }
      },
      fail: function(res) {},
      complete: function(res) {},
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  radioChange:function(e){
    console.log(e);
    var value = e.detail.value;
    wx.setStorageSync('xiaoqu', value);
  },
  goindex:function(){
    wx.switchTab({
      url: '/pages/index/index',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})